<?php
/**
 * Created by PhpStorm.
 * User: xuewl
 * Date: 2017/12/26
 * Time: 18:54
 */

namespace app\api\controller\v1\message;
use app\api\controller\v1\Init;

class Message extends Init
{
    protected $model;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('message/message', 'service');
    }

    /**
     * 获取消息列表
     */
    public function lists() {
        $maps = [];
        $maps['to'] = ["in", [0, $this->user['id']]];
        $maps['role'] = $this->user['role'];

        $order = $this->params['order'] ?: 'id desc';
        $extra = $this->params['extra'] && !is_array($this->params['extra']) ? explode(",", $this->params['extra']) : [];
        $adds = [];
        $attrs = $this->params['attrs'] ? explode(",", $this->params['attrs']) : [];

        $result = $this->model->lists($maps, $this->limit, $this->page, $order, true, $extra, $adds, $attrs);
        return $this->response(lang('Operation completed'), $result);
    }
}